#
# @lc app=leetcode.cn id=104 lang=python3
#
# [104] 二叉树的最大深度
#

# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    
    def maxDepth(self, root: TreeNode) -> int:
    #    def midOrder(treeNode):
    #        if treeNode == None:return
    #        dictA["depths"] += 1
    #        if treeNode.left != None:
    #            midOrder(treeNode.left)       
    #        if treeNode.right != None:
    #            midOrder(treeNode.right)
    #        dictA["maxDepth"] = max(dictA["maxDepth"], dictA["depths"])    
    #        dictA["depths"] -= 1
    #        return
    #    dictA = {"depths":0, "maxDepth":0}
    #    midOrder(root)
        
    #    return dictA["maxDepth"]
        #solution 2:
        return self.maxD(root)
    
    def maxD(self, root):
        if root == None: 
            return 0
        else:
            return max(self.maxD(root.left),self.maxD(root.right)) + 1
             
# @lc code=end

